package icu.ac.kr.simpleRssReader.view;

import icu.ac.kr.simpleRssReader.provider.RssDBProviderConstant;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PostRow extends ViewGroup {

	static final String TAG = "PostRow";
	
	TextView pubdate;
	TextView postID;
	
	public PostRow(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub

		LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
	  	pubdate = new TextView(context);
		postID = new TextView(context);
		
		addView(postID, params);
		addView(pubdate, params);
		
	}

	@Override
	protected void onLayout(boolean changed, int l, int t, int r, int b) {
		// TODO Auto-generated method stub

		int width = getWidth();
		
		postID.layout(0, 0, width, 100);
		pubdate.layout(0, 50, width, 100);
		
	}

	public void bindData(Cursor cursor)
	{
		
		int read = cursor.getInt(cursor.getColumnIndex(RssDBProviderConstant.post.READ));
		postID.setTypeface((read == 0)? Typeface.DEFAULT: Typeface.DEFAULT_BOLD);
		pubdate.setTypeface((read == 0)? Typeface.DEFAULT: Typeface.DEFAULT_BOLD);
		postID.setText("Post ID : " + cursor.getLong(cursor.getColumnIndex(RssDBProviderConstant.post._ID)));
		pubdate.setText(cursor.getString(cursor.getColumnIndex(RssDBProviderConstant.post.PUBDATE)));
			
	}
	
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);

		pubdate.measure(widthMeasureSpec, 100);
		setMeasuredDimension(widthMeasureSpec, 100);
	}

}
